﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Lib.Web.Mvc;

namespace VideoJS.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult VideoJS()
        {
            return View();
        }

        public ActionResult OceansClip(string type)
        {
            FileInfo oceansClipInfo = null;
            string oceansClipMimeType = String.Format("video/{0}", type);

            switch (type)
            {
                case "mp4":
                    oceansClipInfo = new FileInfo(Server.MapPath("~/Content/video/oceans-clip.mp4"));
                    break;
                case "webm":
                    oceansClipInfo = new FileInfo(Server.MapPath("~/Content/video/oceans-clip.webm"));
                    break;
                case "ogg":
                    oceansClipInfo = new FileInfo(Server.MapPath("~/Content/video/oceans-clip.ogv"));
                    break;
            }

            return new RangeFilePathResult(oceansClipMimeType, oceansClipInfo.FullName, oceansClipInfo.LastWriteTimeUtc, oceansClipInfo.Length);
            
            //return new RangeFileStreamResult(oceansClipInfo.OpenRead(), oceansClipMimeType, oceansClipInfo.Name, oceansClipInfo.LastWriteTimeUtc);
            
            //byte[] oceansClipContents = new byte[oceansClipInfo.Length];
            //using (FileStream oceansClipStream = oceansClipInfo.OpenRead())
            //    oceansClipStream.Read(oceansClipContents, 0, oceansClipContents.Length);
            //return new RangeFileContentResult(oceansClipContents, oceansClipMimeType, oceansClipInfo.Name, oceansClipInfo.LastWriteTimeUtc);
        }
    }
}
